package com.sample.abhi.JaxbMoxyImpl.service;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import com.sample.abhi.JaxbMoxyImpl.model.Student;

public class StudentJaxbService {

	public static void unmarshall() throws Exception
	{
		System.out.println("UnMarshalling started...");
		JAXBContext jaxbContext = JAXBContext.newInstance(Student.class);
		Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
		Student student = (Student)unmarshaller.unmarshal(new File("student.xml"));
		System.out.println("UnMarshalling done : Role-"+student.getRollNo()+", First Name-"+student.getFirstName()
				+", Last Name-"+student.getLastName());
	}
	
	public static void marshall(Student student) throws Exception
	{
		System.out.println("Marshalling started...");
		JAXBContext jaxbContext = JAXBContext.newInstance(Student.class);
		Marshaller marshaller = jaxbContext.createMarshaller();
		marshaller.marshal(student,new File("student.xml"));
		System.out.println("Marshalling done : student.xml file generated...");
	}
}
